package base

import "reflect"

// RemoveTypePtr 移除多指针
func RemoveTypePtr(t reflect.Type) reflect.Type {
	for t.Kind() == reflect.Ptr {
		t = t.Elem()
	}
	return t
}

// RemoveValuePtr 移除多指针
func RemoveValuePtr(t reflect.Value) reflect.Value {
	last := t
	for t.Kind() == reflect.Ptr {
		// 防止最外层为空指针的情况, 再处理后返回的无效的
		if t.IsNil() {
			break
		}
		t = t.Elem()
		last = t
	}
	return last
}

// IsExported 是可导出
func IsExported(fieldName string) bool {
	if fieldName == "" {
		return false
	}
	first := fieldName[0]
	return first >= 'A' && first <= 'Z'
}

// InArraySlow 判断 target 是否在 ins
func InArraySlow(target interface{}, ins ...interface{}) bool {
	for _, in := range ins {
		if reflect.DeepEqual(target, in) {
			return true
		}
	}
	return false
}
